<?php
declare (strict_types = 1);

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
use think\facade\Db;

class generateBookingDateTime extends Command{
    protected function configure()
    {
        // 指令配置
        $this->setName('generateBookingDateTime')->setDescription('生成展馆预约时间');
    }

    protected function execute(Input $input, Output $output){
        $where[]=['is_publish','=',1];
        $data=Db::table('activity')->field('id,title,start_time,end_time,fee,is_publish')
        ->where($where)->order('id desc')->select();
        $array=[];
        $weekdayNames = ['周一','周二','周三','周四','周五','周六','周日'];
        foreach ($data as $key => $value) {

            $diffInMinutes=($value['end_time']-$value['start_time'])/(60 * 60 * 24);
            $output->writeln($diffInMinutes.'天');
               for($i=0;$i<=$diffInMinutes;$i++){
                $date_time_timestamp=strtotime(date('Y-m-d',$value['start_time']) . ' + ' . $i . ' days');

                $array[date('Ymd', $date_time_timestamp)]['remaining']=1000;
                // $array[date('Ymd')]['time'][]=['range'=>'09:00-12:00','remaining'=>500];
                // $array[date('Ymd')]['time'][]=['range'=>'12:00-16:00','remaining'=>500];
                $array[date('Ymd', $date_time_timestamp)]['time']=[
                    ['range'=>'09:00-12:00','remaining'=>500],
                    ['range'=>'12:00-16:00','remaining'=>500]
                ];
            }
            // for($i=0;$i<=$diffInMinutes;$i++){
            //     $date_time_timestamp=strtotime(date('Y-m-d',$value['start_time']) . ' + ' . $i . ' days');
            //     $array[$i]['timestamp']=$date_time_timestamp;
            //     $array[$i]['date']=date('m-d', $date_time_timestamp);
            //     $array[$i]['fulldate']=date('Y-m-d', $date_time_timestamp);
            //     $array[$i]['weekday']=$weekdayNames[date('w', $date_time_timestamp)];
            //     $array[$i]['remaining']=1000;
            //     $array[$i]['time'][]=['range'=>'09:00-12:00','remaining'=>500];
            //     $array[$i]['time'][]=['range'=>'12:00-16:00','remaining'=>500];
            // }
            \think\facade\Cache::store('redis')->set('bookingDateTime_By_ActivityId_'.$value['id'],$array,86400*$diffInMinutes);
        }
    }
}